<?php
session_start();
require 'connect.php';

$meSql = "SELECT * FROM books ";
$meQuery = mysql_query($meSql);

$action = isset($_GET['a']) ? $_GET['a'] : "";
$itemCount = isset($_SESSION['cart']) ? count($_SESSION['cart']) : 0;
if(isset($_SESSION['qty'])){
    $meQty = 0;
    foreach($_SESSION['qty'] as $meItem){
        $meQty = $meQty + $meItem;
    }
}else{
    $meQty=0;
}
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>itoffside.com shopping cart</title>

        <!-- Bootstrap -->
        <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
        <link href="bootstrap/css/nava.css" rel="stylesheet">

        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
          <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->

    <style type="text/css">
    body {
	background-color: #FFFFCC;
}
    body,td,th {
	color: #000;
}
    </style>
    </head>
    <body>
        <div class="container">

            <!-- Static navbar -->
            <div class="navbar navbar-default" role="navigation">
              <div class="container-fluid">
                <div class="navbar-collapse collapse">
                  <form name="form1" method="post" action="">
                    <p>&nbsp;</p>
                  </p>
                  </form>
                  <ul class="nav navbar-nav">
                    <li><a href="cart.php">หนังสือที่จอง <span class="badge"><?php echo $meQty; ?></span></a></li>
                  </ul>
              </div><!--/.nav-collapse -->
                </div><!--/.container-fluid -->
            </div>

            <!-- Main component for a primary marketing message or call to action -->

            <h3>หน้าแรกของรายการหนังสือ</h3>
<?php
if($action == 'exists'){
    echo "<div class=\"alert alert-warning\">เพิ่มจำนวนหนังสือแล้ว</div>";
}
if($action == 'add'){
    echo "<div class=\"alert alert-success\">เพิ่มหนังสือลงในตะกร้าเรียบร้อยแล้ว</div>";
}
if($action == 'order'){
	echo "<div class=\"alert alert-success\">จองหนังสือเรียบร้อยแล้ว</div>";
}
if($action == 'orderfail'){
	echo "<div class=\"alert alert-warning\">จองหนังสือไม่สำเร็จ มีข้อผิดพลาดเกิดขึ้นกรุณาลองใหม่อีกครั้ง</div>";
}
?>
            <table width="696" border="1" class="table table-striped">
                <thead>
                    <tr>
                        <th width="79" bgcolor="#FFFFFF">รูปหนังสือ</th>
                        <th width="123" bgcolor="#FFFFFF">รหัสหนังสือ</th>
                        <th width="115" bgcolor="#FFFFFF">ชื่อหนังสือ</th>
                        <th width="85" bgcolor="#FFFFFF">รายละเอียด</th>
                        <th width="112" bgcolor="#FFFFFF">ราคา</th>
                        <th width="72" bgcolor="#FFFFFF">&nbsp;</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    while ($meResult = mysql_fetch_assoc($meQuery))
                    {
                        ?>
                        <tr>
                            <td><img src="images/<?php echo $meResult['picture']; ?>" width="67" height="76" border="0"></td>
                            <td><?php echo $meResult['id']; ?></td>
                            <td><?php echo $meResult['book_name']; ?></td>
                            <td><?php echo $meResult['book_desc']; ?></td>
                            <td><?php echo number_format($meResult['book_price'],2); ?> / วัน</td>
                            <td>
                                <a class="btn btn-primary btn-lg" href="updatecart.php?itemId=<?php echo $meResult['id']; ?>" role="button">
                                    <span class="glyphicon glyphicon-shopping-cart"></span>จอง</a>
                            </td>
                        </tr>
                        <?php
                    }
                    ?>
                </tbody>
            </table>

        </div> <!-- /container -->

        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="bootstrap/js/jquery.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="bootstrap/js/bootstrap.min.js"></script>
    </body>
</html>
<?php
mysql_close();
?>